package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.LoanReviewMapper;
import com.gxa.p2p.pojo.LoanBidsDetail;
import com.gxa.p2p.service.LoanReviewService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author BKP
 * @date 2020.8.6
 */
@Service("loanReviewService")
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT)
public class LoanReviewServiceImpl implements LoanReviewService {

    @Resource
    private LoanReviewMapper loanReviewMapper;

    /**
     * 带条件,且条件含有非空判断的全查询
     * @param map
     * @return list
     */
    @Override
    public List<LoanBidsDetail> findAll(Map<String,Object> map) {
        int page = ((Integer) map.get("page") - 1) * (Integer) map.get("limit");
        map.put("page",page);
        return loanReviewMapper.findAll(map);
    }

    /**
     * 计算带条件的数据总数
     * @param map
     * @return Integer
     */
    @Override
    public Integer dataSum(Map<String,Object> map) {
        return loanReviewMapper.dataSum(map);
    }

    /**
     * 添加审核信息
     * @param LoanBidsDetail
     * @return Integer 修改的行数
     */
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = {Throwable.class})
    @Override
    public Integer updateReviewStatus(LoanBidsDetail loanBidsDetail) {
        loanBidsDetail.setExamineDate(new Date());
        return loanReviewMapper.updateReviewStatus(loanBidsDetail);
    }
}
